#ifndef __SQLGATEWAY_HPP__
#define __SQLGATEWAY_HPP__

#include <string>
#include <set>

#include "mysql++.h"

#include "DataTypes.hpp"
#include "ResultQuote.hpp"


/*
  MySQL++ wrapper class
*/

class SQLGateway
{
public:
   SQLGateway();
public:
   bool Connect();
public:
   std::string getConnectionErrorMessage() { return std::string(this->conn.error()); }
   bool        isConnected() { return this->conn.connected(); }
public:
   bool        getSQLTableFieldNames(std::string tableName, SetString& setFieldNames);
public: 
   bool insertResultQuote(std::string tableName, ResultQuote& resultQuote, SetString& setReturnFieldsNotInTable);
   bool insertResultQuote(std::string tableName, ResultQuote& resultQuote);   
private:
   bool getFieldsNotInTable(std::string tableName, ResultQuote& resultQuote, SetString& setReturnFieldsNotInTable);
   bool insertResultQuote(std::string tableName, ResultQuote& resultQuote, SetString* setReturnFieldsNotInTable = NULL);

public:    // Accessors
   std::string getLastSQLError() { return this->strLastSQLError; }
   std::string getLastSQLQuery() { return this->strLastSQLQuery; }
private:   // Private utility
  bool shouldTypesValueBeQuoted(FieldNameType fieldNameType);
private:
   void clearPreviousError() { this->strLastSQLError.clear(); }
public:
   bool transactionCommit();
   bool transactionRollback();

private:
   std::string strLastSQLError;		// er.what() message from the last exception to occurr
   std::string strLastSQLQuery;         // text of last query executed
   mysqlpp::Connection conn;
   mysqlpp::Transaction* trans;
};

#endif 
